# 定义一个简单的钩子函数
def hook(module, input, output):
    outputs.append(output)

def middle_data(dataloader, model, device):
    i = 0
    correct = 0
    size = len(dataloader.dataset)
    handle = model.fc2.register_forward_hook(hook)                    # 不同的模型在这一行会有所不同
    # 在模型的某一层注册一个钩子，本质是在模型计算的中途运行钩子函数代码
    model.eval()
    with torch.no_grad():
        for X, y in dataloader:
            X = X.to(torch.float32)
            X, y = X.to(device), y.to(device)
            pred = model(X)
            correct += (pred.argmax(1) == y).type(torch.float).sum().item()
#             if i==0:
#                 c_data =  pred
#                 i = i+1
#             else:
#                 c_data = torch.cat((c_data, pred), 0)
#                 i = i+1
    
    correct /= size
    print(f" Error: \n Accuracy: {(100*correct):>0.1f}%  \n")
    return 